<?php
	class message extends Mysql{
		function __construct(){
			parent::__construct();
		}


		// private $table_message="user_message";				//系统消息表
		// private $table_message_list="user_message_list";	//系统消息发送人列表
		
		/**
		 * 发送消息
		 * @param $from_user
		 * @param $to_user
		 * @param $content
		 * @param $title
		 */
		function postMessage($from_user,$to_user,$content,$title=''){
			$datetime=time();
			$arr = array('user_id'=>$from_user,'to_user'=>$to_user,'type'=>'1','title'=>$title,'content'=>$content,'datetime'=>$datetime);
			$this->insert('user_message',$arr);
			$message_id=$this->insert_id();
			$arr = array('user_id'=>$to_user,'to_user'=>$from_user,'type'=>'0','title'=>$title,'content'=>$content,'datetime'=>$datetime);
			$this->insert('user_message',$arr);
			
			return $message_id;
		}
		
		/**
		 * 信息列表
		 * @param $user_id
		 */
		function messageList($user_id){
			$message=common::getList('user_message m',"m.user_id='".$user_id."'","left join user u on u.id=m.to_user",'1','10','m.*,u.name,u.avatar','m.id desc');
			foreach($message['result'] as $k=>$v){
				$message['result'][$k]['avatar']=user::userAvatar($v['to_user']);
			}
			
			return $message;
		}

		/**
		 * 读取系统消息
		 * @author jsy  
		 * @param  string  $where 
		 * @param  string  $key   
		 * @param  integer $num   
		 * @return array 
		 */
		/*function message_sys($where='',$key='c.*',$num=0){
			$sql=$this->table_message_list.' c where 1=1 '.$where;
			$list=$this->getList($sql,$key,$num);
			return $list;
		}*/



	}
?>